package com.necer.utils;

import android.graphics.Rect;
import android.graphics.drawable.Drawable;

public class DrawableUtil {


    /**
     * 获取绘制Drawable的矩形
     */
    public static Rect getDrawableBounds(int centerX, int centerY, Drawable drawable) {
        return new Rect(centerX - drawable.getIntrinsicWidth() / 2,
                centerY - drawable.getIntrinsicHeight() / 2,
                centerX + drawable.getIntrinsicWidth() / 2,
                centerY + drawable.getIntrinsicHeight() / 2);
    }

    public static Rect getDrawableBounds(int centerX, int centerY, int width, int height) {
        // 为了保证是原型，采用小值做位置
        int temp = Math.min(width, height);
        return new Rect(centerX - temp / 2,
                centerY - temp / 2,
                centerX + temp / 2,
                centerY + temp / 2);
    }
}
